package com.vitabuybuy.tv.ui.mine.coin

import android.os.Bundle
import android.view.View
import com.library.common.base.BaseActivity
import com.library.common.base.MessageModel
import com.library.common.ext.setOnclickNoRepeat
import com.vitabuybuy.tv.R
import com.vitabuybuy.tv.databinding.ActivityMyRewardCoinBinding
import com.vitabuybuy.tv.ui.mine.coin.viewmodel.RewardCoinViewModel
import kotlinx.android.synthetic.main.activity_my_reward_coin.*

class MyRewardCoinActivity : BaseActivity<RewardCoinViewModel, ActivityMyRewardCoinBinding>() {
    override val isUseBaseTitleBar: Boolean
        get() = true
    override val layoutId: Int
        get() = R.layout.activity_my_reward_coin

    override fun initView(savedInstanceState: Bundle?) {
        setTitle(getString(R.string.my_reward_coin))
        mBinding.viewModel = viewModel
    }

    override fun onResume() {
        super.onResume()
        viewModel.getMyCoin()
    }
    override fun eventHandling() {
        setOnclickNoRepeat(rlRecharge, rlUseRecord){v->
            when (v) {
                rlRecharge -> {
                    RechargeRewardCoinActivity.openActivity(mContext,tvBalance.text.toString().toInt())
                }
                rlUseRecord -> {
                    UseRecordActivity.openActivity(mContext)
                }
            }
        }
    }

    override fun handleEvent(msg: MessageModel) {
        when(msg.code){
            2->{
                tvBalance.text = msg.arg1.toString()
            }
        }
    }

    companion object{
        fun openActivity(mContext:BaseActivity<*,*>){
            mContext.startActivity(null,MyRewardCoinActivity::class.java)
        }
    }
}
